﻿using Abp.Dependency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core.Runtime.Caching
{
    /// <summary>
    /// 基本缓存
    /// </summary>
    public interface IBaseCache : IDisposable
    {
        /// <summary>
        /// 名称
        /// </summary>
        string Name { get; }

        /// <summary>
        /// 默认过期时间
        /// </summary>
        TimeSpan? DefaultExpireTime { get; set; }

        /// <summary>
        /// 清除缓存
        /// </summary>
        void Clear();

        /// <summary>
        /// 异步清除缓存
        /// </summary>
        /// <returns></returns>
        Task ClearAsync();

        /// <summary>
        /// 获取或添加
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="factory">工厂</param>
        /// <returns></returns>
        T GetOrAdd<T>(string key, Func<string, T> factory);

        /// <summary>
        /// 异步获取或添加
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="factory">工厂</param>
        /// <returns></returns>
        Task<T> GetOrAddAsync<T>(string key, Func<string, Task<T>> factory);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<T> GetAsync<T>(string key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        void Remove(string key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        Task RemoveAsync(string key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireTime"></param>
        void Set<T>(string key, T value, TimeSpan? expireTime = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireTime"></param>
        /// <returns></returns>
        Task SetAsync<T>(string key, T value, TimeSpan? expireTime = null);
    }
}
